package april;

import com.sun.deploy.security.CredentialManager;

/**
 * @author ：冯涛滔
 * @date ：Created in 2020-4-18 22:08
 * @description：
 * @modified By：
 * @version:
 */
public class April18 {
    /**
     * create by: 冯涛滔
     * description: https://leetcode-cn.com/problems/container-with-most-water/
     * create time: 2020-4-18 22:08
     * @params [height]
     * @return int
     */
//    public static int maxArea() {
//        int[] height = {1,8,6,2,5,4,8,3,7};
//       int left = 0;
//       int right =1;
//       int maxSize = Math.min(height[left],height[right])*(right-left);
//        for (int i = 2; i < height.length; i++) {
//            int leftMax = Math.min(height[left], height[i]) * (i - left); //左指针不变
//            int rightMax = Math.min(height[right], height[i]) * (i - right); //右指针不变
//            if(leftMax>rightMax){
//                if(leftMax>maxSize){
//                    right = i;
//                    maxSize = leftMax;
//                }
//            }else{//右比较大
//                if(rightMax>maxSize){
//                    left = right;
//                    right = i;
//                    maxSize = rightMax;
//                }
//            }
//            System.out.println(maxSize+"left:"+left+"right"+right);
//        }
//        return maxSize;
//    }
//    public static int maxArea2() {
//        int left = 0;
//        int right =1;
//        int maxSize = Math.min(height[left],height[right])*(right-left);
//        while(left<right&&right<height.length-1){
//            if(Math.min(height[left],height[right+1])*(right+1-left)>maxSize){
//                right++;
//                maxSize = Math.min(height[left],height[right])*(right-left);
//            }else{
//                if(Math.min(height[left+1],height[right])*(right-(left+1))>maxSize){
//                    left++;
//                    maxSize = Math.min(height[left],height[right])*(right-left);
//                }else{
//                    return maxSize;
//                }
//            }
//
//        }
//        return maxSize;
//    }
    public static  int maxArea(){
        int[] height = {1,8,6,2,5,4,8,3,7};
        int left = 0;
        int right = height.length-1;
        int maxSize = Math.min(height[left],height[right])*(right-left);
        while(left<right){
            if(height[right]>=height[left]){
                left++;
            }else{
                right--;
            }
            int count = Math.min(height[left],height[right])*(right-left);
            if(maxSize<count){
                maxSize = count;
            }
        }
        return maxSize;
    }
    public static void main(String[] args)   {
        April18 april18 = new April18();
        Thread t1 = new Thread(april18::printNumber);
        Thread t2 = new Thread(april18::printEnglish);
        t1.start();
        t2.start();
    }
    public synchronized void printNumber()  {
        for (int i = 1; i <=52 ; i++) {
            System.out.print(i+" ");
            this.notify();
            if(i%2==0){
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public synchronized void printEnglish(){
        for (int i = 0; i < 26 ; i++) {
            System.out.println((char) (65 + i));
            this.notify();
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            ;
        }
    }
}

